package com.zls.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zls.mapper.TFarmMapper;
import com.zls.page.PageResult;
import com.zls.page.QueryPageBean;
import com.zls.pojo.SysUser;
import com.zls.pojo.TFarm;
import com.zls.service.TFarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class TFarmServiceImpl extends ServiceImpl<TFarmMapper, TFarm> implements TFarmService {
    @Autowired
    private TFarmMapper tFarmMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();//当前页
        Integer pageSize = queryPageBean.getPageSize();//每页大小
        String queryString = queryPageBean.getQueryString();//查询条件
        //total总记录数
        List<TFarm> page = tFarmMapper.findPage((currentPage - 1) * pageSize, pageSize,queryString);
        //rows  当前页的数据
        Long count = tFarmMapper.count(queryString);
        pageResult.setRows(page);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    @Transactional
    public int addFTarm(TFarm tFarm) {
        tFarm.setCreateTime(new Date());
        tFarm.setUpdateTime(new Date());
        int insert = tFarmMapper.insert(tFarm);
        return insert;
    }

    @Override
    public TFarm selectId(int id) {
        return tFarmMapper.selectId(id);
    }

    @Override
    @Transactional
    public int editTFarm(TFarm tFarm) {
        tFarm.setUpdateTime(new Date());
        int i = tFarmMapper.updateById(tFarm);
        return i;
    }


}
